Load libraries

library(here)
## here() starts at /Users/leahreichert/Documents/Tidy-Tuesday
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2
## ──
## ✔ ggplot2 3.4.1     ✔ purrr   1.0.1
## ✔ tibble  3.1.8     ✔ dplyr   1.1.0
## ✔ tidyr   1.3.0     ✔ stringr 1.5.0
## ✔ readr   2.1.3     ✔ forcats 1.0.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(ggplot2)
library(gganimate)

Introduction

Today I will be practicing with animation.

Load data

soccer21_22 <- read_csv(here("TidyTuesday 6", "Data", "soccer21-22.csv"))
## Rows: 380 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (6): Date, HomeTeam, AwayTeam, FTR, HTR, Referee
## dbl (16): FTHG, FTAG, HTHG, HTAG, HS, AS, HST, AST, HF, AF, HC, AC, HY, AY, ...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
View(soccer21_22)

Plot Data: practice with animation

soccer21_22 %>%
  ggplot(aes(x = FTHG,
             y = FTAG,
         color = HomeTeam)) +
  geom_point() +
  transition_states(
    HomeTeam, # what I'm animating by 
    transition_length = 4, # length of transition 
    state_length = 2 # the length of the pause in between
  ) +
  labs(x = "FTHG",
       y = "FTAG",
       title = "Home Team: FTHG vs. FTAG") +
  theme_bw() +
  theme(panel.background = element_rect(fill = "gray97" ))+
  theme(plot.background = element_rect(fill = "lavender"))